package guoanmaker.operator.business.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorRefuselist;
import guoanmaker.operator.business.service.OperatorRoomServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_ACTIVITY_TYPE)
public class OperatorRoomController {
	
	@Autowired
	private AjaxJson ajaxJson;
	
	@Autowired
	private OperatorRoomServiceInterface operatorRoomServiceInterface;
	
	@ApiOperation(value="根据空间的状态查询空间list", notes="根据空间的状态查询空间list")
	@PostMapping("/selectRoomListByStauts")
	public  AjaxJson selectRoomListByStauts(Integer roomState,Integer page, Integer size){
		try {
			Map<String,Object> map=operatorRoomServiceInterface.selectRoomListByStauts(roomState,page,size);
			int a=(int) map.get("count");
			if(a>0){
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
			else{
				ajaxJson.setSuccess(true).setStatus(250).setData("没有数据");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
			
		return ajaxJson;
	}
	
	@ApiOperation(value="根据空间id查询空间详情", notes="根据空间id查询空间详情")
	@PostMapping("/selectRoomByRoomId")
	public  AjaxJson selectRoomByRoomId(String roomId){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.selectRoomByRoomId(roomId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="根据空间id查询审批记录", notes="根据空间id查询审批记录")
	@PostMapping("/selectRefuseBYRoomId")
	public  AjaxJson selectRefuseBYRoomId(String roomId){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.selectRefuseBYRoomId(roomId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="同意审核", notes="同意审核")
	@PostMapping("/roomConsentAudit")
	public  AjaxJson roomConsentAudit(String roomId,String userId){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.roomConsentAudit(roomId,userId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("审核失败");
		}
		
		return ajaxJson;
	}
	@ApiOperation(value="查询空间审核拒绝原因列表", notes="查询空间审核拒绝原因列表")
	@PostMapping("/selectOperatorRefuselist")
	public  AjaxJson selectOperatorRefuselist(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.selectOperatorRefuselist());
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="拒绝空间审核提交", notes="拒绝空间审核提交")
	@PostMapping("/RefuseRoomApplication")
	public  AjaxJson RefuseRoomApplication(String reasonName,String content,String userId,String roomId){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.RefuseRoomApplication(reasonName,content,userId,roomId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("提交失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="关闭已审核空间提交", notes="关闭已审核空间提交")
	@PostMapping("/CloseRoomAudit")
	public  AjaxJson CloseRoomAudit(String reasonName,String content,String userId,String roomId){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.CloseRoomAudit(reasonName,content,userId,roomId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("提交失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="查询空间审核拒绝原因列表加分页", notes="查询空间审核拒绝原因列表加分页")
	@PostMapping("/selectOperatorRefuselistPage")
	public  AjaxJson selectOperatorRefuselistPage(Integer page, Integer size ,String keyName){
		try {
			Map<String,Object> map=operatorRoomServiceInterface.selectOperatorRefuselistPage(page,size,keyName);
			int a=(int) map.get("count");
			if(a>0){
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
			else{
				ajaxJson.setSuccess(true).setStatus(250).setData("没有数据");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="新增空间原因分类", notes="新增空间原因分类")
	@PostMapping("/insertRoomRefuselist")
	public  AjaxJson insertRoomRefuselist(String categoryName,String userId){
		try {
			OperatorRefuselist operatorRefuselist=operatorRoomServiceInterface.insertRoomRefuselist(categoryName,userId);
			if(operatorRefuselist==null){
				ajaxJson.setSuccess(true).setStatus(230).setData("该原因已存在");
			}
			else{
				ajaxJson.setSuccess(true).setStatus(200).setData(operatorRefuselist);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("插入失败");
		}
		
		return ajaxJson;
	}
	
	@ApiOperation(value="根据删除空间原因分类", notes="根据删除空间原因分类")
	@PostMapping("/deleteRoomRefuselist")
	public  AjaxJson deleteRoomRefuselist(String refuseId){
		try {
			operatorRoomServiceInterface.deleteRoomRefuselist(refuseId);
			ajaxJson.setSuccess(true).setStatus(200).setData("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("删除失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="根据原因id修改原因名称", notes="根据原因id修改原因名称")
	@PostMapping("/updateRoomRefuselist")
	public  AjaxJson updateRoomRefuselist(String refuseId,String categoryName){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.updateRoomRefuselist(refuseId,categoryName));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("修改失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="根据配套设施的多个id串查询配套设施", notes="根据配套设施的多个id串查询配套设施")
	@PostMapping("/selectSpacefacilitiesByIds")
	public  AjaxJson selectSpacefacilitiesByIds(String ids){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoomServiceInterface.selectSpacefacilitiesByIds(ids));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询审核记录列表加分页", notes="查询审核记录列表加分页")
	@PostMapping("/selectOperatorRefuseRecordPage")
	public  AjaxJson selectOperatorRefuseRecordPage(String username,String refusename,String startDate,String endDate,Integer page,Integer size){
		try {
			Map<String,Object> map=operatorRoomServiceInterface.selectOperatorRefuseRecordPage(username,refusename,startDate,endDate,page,size);
			int a=(int) map.get("count");
			if(a>0){
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
			else{
				ajaxJson.setSuccess(true).setStatus(250).setData("没有数据");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	
}
